#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include "libSbNet.h"
using namespace std;

int main(int argc, char *argv[])
{
	int retValue = 0; 
	if(argc < 2) {
		printf("Incorrect number of args\n");
		printf("Args: trace file\n");
		retValue = 1;
	}

	string line;

	ifstream traceFile (argv[1]);
	if (traceFile.is_open())
  	{
    		while (traceFile.good())
    		{
      			getline(traceFile,line);
			if (line.size()>0)
			{
				istringstream iss(line);
				string strSub;
				iss >> strSub;
				
				string strLocalFile;
				libSbNet sb;
				if (sb.loadCfg()==0)
				{
					strLocalFile = sb.sbGetTurl(strSub);
					cout << "Catalog File Name: " << strSub << endl;
			        }
				
				if (strLocalFile.empty())
				{
					cout<<" We have an error, cannot download the file " << strSub << endl;
				} else {
					char * localFileName = const_cast<char*> ( strLocalFile.c_str() );
			        	cout << "Local file Name: " << localFileName << endl;
				}
	
			}
    		}
    	traceFile.close();
  	}
	else cout << "Unable to open file"; 

	return retValue;
}

